var my_ztree = function() {

	var select_menu_radio = function(zNodes){
		var setting = {
				check: {
					enable: true,
					chkStyle: "radio",
					radioType: "all"
				},
				view: {
					dblClickExpand: false
				},
				data: {
					simpleData: {
						pIdKey:"pid",
						enable: true
					}
				},
				callback: {
					onClick: onClick,
					onCheck: onCheck
				}
			};

			$.fn.zTree.init($("#tree_menu"), setting, zNodes);
			$.fn.zTree.getZTreeObj("tree_menu").expandAll(true);
			function onClick(e, treeId, treeNode) {
				var zTree = $.fn.zTree.getZTreeObj("tree_menu");
				zTree.checkNode(treeNode, !treeNode.checked, null, true);
				
				return false;
			}

			function onCheck(e, treeId, treeNode) {
				var zTree = $.fn.zTree.getZTreeObj("tree_menu"),
				nodes = zTree.getCheckedNodes(true),
				v = "";
				for (var i=0, l=nodes.length; i<l; i++) {
					v += nodes[i].name + ",";
				}
				if (v.length > 0 ) v = v.substring(0, v.length-1);
				$("#pid_name").attr("value", v);
				$("#pid").attr("value", treeNode.id);
				hideMenu();
			}

	};
	
	var showMenu = function(){
		$("#menuContent").slideDown("fast");
		$("body").bind("mousedown", onBodyDown);
	};
	
	var hideMenu = function(){
		$("#menuContent").fadeOut("fast");
		$("body").unbind("mousedown", onBodyDown);
	};
	
	var onBodyDown = function(event){
		if (!(event.target.id == "menuBtn" || event.target.id == "menuList" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
			hideMenu();
		}
	};
	
	return {
		select_menu_radio : select_menu_radio,
		showMenu : showMenu,
	};
	
}();
